package main.二分查找;

/**
 * @author tmh
 * @date 2024/7/24 19:17
 * @description
 */
public class T74搜索二维矩阵 {
    public boolean searchMatrix(int[][] matrix, int target) {
        //对每一行都进行二分遍历
        int row = matrix.length;
        int col = matrix[0].length;
        for (int i = 0; i < row; i++) {
            int low = 0;
            int high = col - 1;
            while (low <= high) {
                int mid = low + ((high - low) >> 2);
                if (matrix[i][mid] > target) {
                    high = mid - 1;
                } else if (matrix[i][mid] < target) {
                    low = mid+1;
                }else {
                    return true;
                }
            }
        }
        return false;
    }
}
